﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewsCategoryList.aspx.cs"
    Inherits="admin_Modules_NewsEvent_Dialog_NewsCategoryList" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="/admin/resources/js/base.js" type="text/javascript"></script>
    <script language="javascript">
        var text = "";
        var value = "";

        function loadForSelect() {
            var node = treeViewCategoryList.getRootNode();
            while (node.firstChild) {
                node.removeChild(node.firstChild);
            }
            Ext.net.DirectMethods.NodeLoad(node.id, {
                success: function (result) {
                    var data = eval("(" + result + ")");
                    node.loadNodes(data);
                    //                    var myMask = new Ext.LoadMask(wdProductCategoryList.getBody(), { msg: "Đang nạp dữ liệu..." });
                    //                    myMask.hide();
                },
                before: function () {
                    //                    var myMask = new Ext.LoadMask(wdProductCategoryList.getBody(), { msg: "Đang nạp dữ liệu..." });
                    //                    myMask.show();
                },
                failure: function (errorMsg) {
                    Ext.Msg.alert('Failure', errorMsg);
                }
            });
        }

        // Hàm xử lí trên Treepanel chọn chuyên mục
        function removeAllCheckNodes(node) {
            var nodeArray = node.childNodes;
            for (var i = 0; i < nodeArray.length; i++) {
                if (nodeArray[i].getUI().checkbox != undefined &&
                                    nodeArray[i].getUI().checkbox.checked == true) {
                    nodeArray[i].getUI().checkbox.checked = false;
                }
                if (nodeArray[i].hasChildNodes())
                    removeAllCheckNodes(nodeArray[i]);
            }
        }

        function checkNodeIsSelected(node) {
            var nodeArray = node.childNodes;
            for (var i = 0; i < nodeArray.length; i++) {
                if (nodeArray[i].getUI().checkbox != undefined &&
                                    nodeArray[i].getUI().checkbox.checked == true) {
                    text += nodeArray[i].text;
                    text += ",";
                    value += nodeArray[i].id;
                    value += ",";
                }
                if (nodeArray[i].hasChildNodes())
                    checkNodeIsSelected(nodeArray[i]);
            }
        }

        function checkRoot(value) {
            var node = treeViewCategoryList.getRootNode();
            node.getUI().checkbox.checked = value;
        }


        function checkChange(node) {
            if (node.getUI().checkbox.checked == false) {
            } else {
                var root = treeViewCategoryList.getRootNode();
                removeAllCheckNodes(root);
                node.getUI().checkbox.checked = true;

                if (node.id.toString() != "0") {
                    //checkRoot(false);
                }

                hdfParentCategoryID.setValue(node.id);
                hdfParentText.setValue(node.text);
            }
        }

     

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ScriptManager2" runat="server">
        <Listeners>
            <DocumentReady Handler="loadForSelect();" />
        </Listeners>
    </ext:ResourceManager>
    <ext:Hidden runat="server" ID="hdfParentText">
    </ext:Hidden>
    <ext:Hidden ID="hdfParentCategoryID" runat="server" />
    <ext:Viewport ID="wdProductCategoryList" runat="server" Layout="BorderLayout">
        <Items>
            <ext:TreePanel ID="treeViewCategoryList" runat="server" Border="true" Header="false"
                RootVisible="false" Region="Center" AutoScroll="true" Title="Chuyên mục tin bài"
                SingleExpand="false">
                <Root>
                    <ext:AsyncTreeNode NodeID="0" Text="Chuyên mục tin bài" SingleClickExpand="true"
                        Expanded="true" Icon="House" />
                </Root>
                <Listeners>
                    <CheckChange Handler="checkChange(node);" />
                </Listeners>
                <TopBar>
                    <ext:Toolbar ID="Toolbar21" runat="server">
                        <Items>
                            <ext:Button Icon="Accept" Text="Chọn">
                                <DirectEvents>
                                    <Click OnEvent="OnSelect" Before="Ext.Msg.wait('Đang cập nhật dữ liêu...', 'Saving'); "
                                        Success="closeWindow();">
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
            </ext:TreePanel>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>
